<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>往来单位分类管理</title>
<%@ include file="/WEB-INF/pages/common/frameCommonJs.jsp"  %>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/commonService.js'></script>
<script>
   var getClassUrl = "<%=request.getContextPath()%>/organization/getAllOrganizationClassJson.action";
   $(function(){
   		$('.icon-reload').click(
			function (){ 
				$('#ocTree').tree('reload')
			}
		);
		$(".icon-reload").css("cursor","pointer");
		$('#ocTree').tree({
			animate: true,
			url: getClassUrl,
			onBeforeExpand:function(node){
				$('#ocTree').tree("options").url=getClassUrl + "?oc.id=" + node.id;
			},
			onClick:function(node){
				var node = $('#ocTree').tree('getSelected');
				$('#orgs').datagrid('reload',{orgClassId:node.id});
				$('#orgClassId').val(node.id);//点击类别的时候，将当前类别Id设置到查询表单中
				$('#orgs').datagrid({pageNumber:1});
			},
			onContextMenu: function(e, node){
				e.preventDefault();
				$('#ocTree').tree('select', node.target);
				$('#mm').menu('show', {
					left: e.pageX,
					top: e.pageY
				});
			}
			
		});
		// 右侧表单内容
		$('#orgs').datagrid({
		 		nowrap: false,
				striped: true,
				collapsible:true,
				fit : true,
				fitColumns : true,	
				url:'<%=request.getContextPath()%>/organization/getOrgsByOrgClassJson.action',
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'code',
				singleSelect:true,
				title:'往来单位列表',
				columns:[[
					{field:'name',title:'名称',width:120},
					{field:'orgClassName',title:'类别',width:120},
					{field:'contactPerson',title:'联系人',width:120},
					{field:'phone',title:'联系电话',width:120,rowspan:2},
					{field:'fax',title:'传真',width:120,rowspan:2},
					{field:'email',title:'邮箱',width:150,rowspan:2},
					{field:'address',title:'地址',width:150,rowspan:2}
				]],
				pageSize:15,  
                pageList:[5,10,15,20],  
                fitColumns: true,  
				pagination:true,
				rownumbers:true
			});
   });
   // 新增往来单位
   function newOrg(){
		title = "新增往来单位信息";
   		$('#dlg').dialog('open').dialog('setTitle',title);  
	    $('#fm').form('clear');  
	    url = '<%=request.getContextPath()%>/organization/saveOrganizationJson.action'; 
   }
   function editOrg(){
   		var node = $("#orgs").datagrid('getSelected');
   		var title = "修改[" + node.name + "]往来单位信息";
   		$('#dlg').dialog('open').dialog('setTitle',title);
   		$("#o\\.id").val(node.id);
   		$("#o\\.name").val(node.name);
   		$("#o\\.bankNo").val(node.bankNo);
   		$("#o\\.contactPerson").val(node.contactPerson);
   		$("#o\\.phone").val(node.phone);
   		$("#o\\.fax").val(node.fax);
   		$("#o\\.email").val(node.email);
   		$("#o\\.zipCode").val(node.zipCode);
   		$("#o\\.address").val(node.address);
   		$("#o\\.note").val(node.note);
   		$("#o\\.orgClassName").val(node.orgClassName);
	    url = '<%=request.getContextPath()%>/organization/updateOrganizationJson.action'; 
   }
   function deleteOrg(){
   		var node = $('#orgs').datagrid('getSelected');
   		var condt = new delOrgProWhCondtn();
   		condt.orgid = node.id;
   		commonService.valDelOrgProWH(condt,function(data){
   			if(data=="no"){
				$.messager.alert("提示信息","该往来单位已在业务单据中使用，不能删除!",'warning');
				return;
	        }
   			$.messager.confirm('删除往来单位信息', '确认删除[' + node.name + ']吗?', function(r){
				if(r){
					$.ajax({
						type:"post",
						data:"o.id=" + node.id,
						url:"<%=request.getContextPath()%>/organization/deleteOrg.action",
						success:function(result){
							var data = eval('(' + result + ')');
							$.messager.show({title:"提示信息",msg:"删除成功",showType:'slide'});
							$('#orgs').datagrid('reload');
						}
					});
					
				}
			});
   		});
   }
   function saveOrg(){  
	    $('#fm').form('submit',{  
	        url: url,  
	        onSubmit: function(){  
	        	var orgClass = $("#o\\.orgClassName").val();
	        	if(orgClass.length == 0){
	        		$.messager.alert("提示信息","请选择类别!",'warning');
	        		return false;
	        	}
	            return $(this).form('validate');  
	        },  
	        success: function(result){  
	       		var result = eval('('+result+')');
	        	// 重读该分类
	        	$("#orgs").datagrid('reload');
	        	var msg = result.name ;
	        	if($("#oc\\.id").val()!=""){
	        		msg = msg + "修改成功!";
	        	}else{
	        		msg = msg + "新增成功!";
	        	}
            	$.messager.show({title:"提示信息",msg:msg,showType:'slide'});
                $('#dlg').dialog('close');      // close the dialog  
	        }  
	    });  
	} 
</script>
</head>
<body class="easyui-layout" >
<div region="west" iconCls="icon-reload" title="往来单位类别" split="true" style="width:180px;">
		<ul id="ocTree"></ul>
</div>
<div region="center" title="往来单位信息管理" split="true">
	<div class="easyui-layout" data-options="fit:true">
		<div style="height:31px" data-options="region:'north',border:false">
			<div id="tb" class="datagrid-toolbar">  
			    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:newOrg()">新增</a>  
			   <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:editOrg()">修改</a>  
			   <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:deleteOrg()">删除</a>  
			</div>
		</div>
		<div data-options="region:'center',border:false">
			<table id="orgs"></table>
		</div>
	</div>
</div>
<div id="dlg" class="easyui-dialog" style="width:500px;height:280px;"  
        closed="true" buttons="#org-dlg-buttons">  
    <form id="fm" method="post"> 
    <table border="0" >
            <tr>
            	<td>名称</td>
            	<td><input type="text" id="o.name" name="o.name"  class="easyui-validatebox"  required="true" />
            		<font color="red">*</font>
            	</td>
            	<input type="hidden" id="o.id" name="o.id" value="" />
            	<input type="hidden" id="o.oc.id" name="o.oc.id" value="" />
            	<td>类别:</td>
            	<td>
            		<input type="text" name="o.orgClassName" id="o.orgClassName" class="easyui-validatebox" readonly="readonly" onclick="openSelectOC()" style="PADDING-LEFT: 20px;BACKGROUND-IMAGE: url(<%=request.getContextPath()%>/images/note_add.png); BACKGROUND-REPEAT: no-repeat;cursor:pointer;" size="17" /> 
            		<font color="red">*</font>
            	</td>
            </tr> 
            <tr>
            	<td>银行帐号</td>
            	<td><input type="text" id="o.bankNo" name="o.bankNo" required="true" /></td>
            	<td>联系人</td>
            	<td><input type="text" id="o.contactPerson" name="o.contactPerson" required="true" /></td>
            </tr>  
            <tr>
            	<td>联系电话</td>
            	<td><input type="text" id="o.phone" name="o.phone" required="true" /></td>
            	<td>传真</td>
            	<td><input type="text" id="o.fax" name="o.fax" required="true" /></td>
            </tr>
            <tr>
            	<td>邮箱</td>
            	<td><input type="text" id="o.email" name="o.email" required="true" /></td>
            	<td>邮编</td>
            	<td><input type="text" id="o.zipCode" name="o.zipCode" required="true" /></td>
            </tr>
            <tr>
            	<td>地址</td>
            	<td><input type="text" id="o.address" name="o.address" required="true" /></td>
            	<td >备注</td>
            	<td colspan="3"><textarea id="o.note" name="o.note" ></textarea></td>
            </tr>
	</table>  
    </form>
</div>
<div id="org-dlg-buttons">  
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveOrg()">保存</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
</div>   
<%@ include file="/WEB-INF/pages/common/orgClassSelect.jsp"  %>
</body>
</html>